
import 'package:flutter/material.dart';
import 'package:fyi/common/common_map.dart';
import 'package:fyi/common/constant.dart';
import 'package:fyi/pages/login_page.dart';
import 'package:fyi/utils/common_util.dart';
import 'package:fyi/utils/navigator_util.dart';
import 'package:fyi/utils/sp_util.dart';

class SplashPage extends StatefulWidget {
  static final String sName = "/";

  @override
  _SplashPageState createState() => _SplashPageState();
}

class _SplashPageState extends State<SplashPage>  {

  bool hadInit = false;

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    if(hadInit) {
      return;
    }
    hadInit = true;

    new Future.delayed(const Duration(seconds: 1), () {
      //NavigatorUtil.goLogin(context);
      _init().then((value){
        NavigatorUtil.goLogin(context);
      }).catchError((err){

      });
    });
  }

  Future<Null> _init()async{
    var languageCode = await SPUtil.get(Constant.LOCALE_LANGUAGE_CODE);
    var countryCode = await SPUtil.get(Constant.LOCALE_COUNTRY_CODE);
    var token = await SPUtil.get(Constant.TOKEN);
    CommonMap.instance.put(Constant.LOCALE_LANGUAGE_CODE, languageCode);
    CommonMap.instance.put(Constant.LOCALE_COUNTRY_CODE, countryCode);
    CommonMap.instance.put(Constant.TOKEN, token);
    CommonUtil.changeLocaleLanguage();
    return null;
  }

  @override
  Widget build(BuildContext context) {
    return new Container(
      color: Colors.grey,
      alignment: Alignment.center,
      child: Image.asset("assets/images/ic_tag_2.png",width:180,height: 68,),
    );
  }

}
